<template>
	<view class="mainbgc">
		<header-top :messageInfo="{typeFlag:true,message:'优惠券',liner:false}">
			<view class="rightmsg" slot="rightmsg">
				<view class="rightmsg_content flexleft" @click="changetype">{{goods_type==1?"全部商品":"部分商品"}}</view>
			</view>
		</header-top>
		<view class="mainpadding2">
			<view class="flexcenter" v-if="!list.data.length">
				<view class="placeholderimage"></view>
			</view>
			<view class="mainpadding_top ffffff radius" style="position: relative;" v-for="item in list.data" :key="item.id" @click="checkRule(item)">
				<view class="xiaobig" v-show="item.goods_type==1">全部商品</view>
				<view class="xiaobig" v-show="item.goods_type==2">部分商品</view>
				<view class="titletext">{{item.name}}</view>
				<view class="flexbetween margin_top xiaohui">
					<view>满减金额:{{item.mj_price}}</view>
					<view>有效天数:<text style="color: #0BCB41;">{{item.days}}</text>天</view>
				</view>
				<view class="flexbetween margin_top xiaohui">
					<view>优惠金额:{{item.price}}</view>
				</view>
				<view class="margin_top xiaohui">
					<view>备注:{{item.note}}</view>
				</view>
			</view>
		</view>
		<u-modal :show="modalShow" title="请输入数量" showCancelButton @cancel="modalShow=false" @confirm="madalconfirm">
			<view class="slot-content">
				<input type="number" style="text-align: center;" placeholder="数量" v-model="num">
			</view>
		</u-modal>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				type: 1, //1客户预收款
				page: 1,
				limit: 12,
				list: {
					data: [],
					is_all: false
				},
				modalShow:false,
				listitem:{},
				num:"",
				goods_type:1,
			}
		},
		onLoad(options) {
			this.type = options.type
			this.init()
		},
		methods: {
			init(isPage, page) {
				let _this = this;
				httpRequest.request('/dhtapi/index/couponList', 'GET', {
					page: page || 1,
					limit: _this.limit,
					goods_type: this.goods_type, //1全部商品，2部分商品
				}, false, false, true).then(res => {
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							_this.list = resList
							_this.list.data = resList.data;
						}
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
			checkRule(item){
				this.listitem = item
				this.modalShow = true
			},
			madalconfirm(){
				this.modalShow = false
				let data = {
					coupon_id:this.listitem.id,
					num:this.num,
					name:this.listitem.name
				}
				if(this.num){
					uni.$emit("yhqSelectFn",data)
				}
				uni.navigateBack(1)
			},
			changetype(){
				this.goods_type = this.goods_type==1?2:1
				this.init()
			}
		}
	}
</script>

<style>
	.xiaobig {
		position: absolute;
		right: 0;
		top: 0;
		font-size: 20rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #0BBDCB;
		display: flex;
		justify-content: center;
		align-items: center;
		width: 100rpx;
		background: #e7f9fa;
		height: 36rpx;
		border-radius: 0 20rpx 0 20rpx;
	}
</style>